<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Fiddle::Pointer - fiddle: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-5B-5D">::[]</a>
    <li ><a href="#method-c-malloc">::malloc</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-read">::read</a>
    <li ><a href="#method-c-to_ptr">::to_ptr</a>
    <li ><a href="#method-c-write">::write</a>
    <li ><a href="#method-i-2B">#+</a>
    <li ><a href="#method-i-2B-40">#+@</a>
    <li ><a href="#method-i-2D">#-</a>
    <li ><a href="#method-i-2D-40">#-@</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-call_free">#call_free</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-free">#free</a>
    <li ><a href="#method-i-free-3D">#free=</a>
    <li ><a href="#method-i-freed-3F">#freed?</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-null-3F">#null?</a>
    <li ><a href="#method-i-ptr">#ptr</a>
    <li ><a href="#method-i-ref">#ref</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-size-3D">#size=</a>
    <li ><a href="#method-i-to_i">#to_i</a>
    <li ><a href="#method-i-to_int">#to_int</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-to_str">#to_str</a>
    <li ><a href="#method-i-to_value">#to_value</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Fiddle::Pointer">
    <h1 id="class-Fiddle::Pointer" class="class">
      class Fiddle::Pointer
    </h1>

    <section class="description">
    
<p><a href="Pointer.html"><code>Fiddle::Pointer</code></a> is a class to handle C pointers</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer[val]         &rarr; cptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_ptr(val)  &rarr; cptr
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Get the underlying pointer for ruby object <code>val</code> and return it as a <a href="Pointer.html"><code>Fiddle::Pointer</code></a> object.</p>

                              <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
{
    VALUE ptr, wrap = val, vptr;

    if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
        rb_io_t *fptr;
        FILE *fp;
        GetOpenFile(val, fptr);
        fp = rb_io_stdio_file(fptr);
        ptr = rb_fiddle_ptr_new(fp, 0, NULL);
    }
    else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
        char *str = StringValuePtr(val);
        wrap = val;
        ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
    }
    else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
        if (rb_obj_is_kind_of(vptr, rb_cPointer)){
            ptr = vptr;
            wrap = 0;
        }
        else{
            rb_raise(rb_eFiddleDLError, &quot;to_ptr should return a Fiddle::Pointer object&quot;);
        }
    }
    else{
        VALUE num = rb_Integer(val);
        if (num == val) wrap = 0;
        ptr = rb_fiddle_ptr_new(NUM2PTR(num), 0, NULL);
    }
    if (wrap) RB_OBJ_WRITE(ptr, &amp;RPTR_DATA(ptr)-&gt;wrap[0], wrap);
    return ptr;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-malloc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer.malloc(size, freefunc = nil)  &rarr; fiddle pointer instance
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer.malloc(size, freefunc) { |pointer| ... } &rarr; ...
                              </span>
                            </div>

                            <div class="method-description">
                              <h2 id="method-c-malloc-label-Examples">Examples<span><a href="#method-c-malloc-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre># Automatically freeing the pointer when the block is exited - recommended
Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) do |pointer|
  ...
end

# Manually freeing but relying on the garbage collector otherwise
pointer = Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE)
...
pointer.call_free

# Relying on the garbage collector - may lead to unlimited memory allocated before freeing any, but safe
pointer = Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE)
...

# Only manually freeing
pointer = Fiddle::Pointer.malloc(size)
begin
  ...
ensure
  Fiddle.free pointer
end

# No free function and no call to free - the native memory will leak if the pointer is garbage collected
pointer = Fiddle::Pointer.malloc(size)
...</pre>

<p>Allocate <code>size</code> bytes of memory and associate it with an optional <code>freefunc</code>.</p>

<p>If a block is supplied, the pointer will be yielded to the block instead of being returned, and the return value of the block will be returned. A <code>freefunc</code> must be supplied if a block is.</p>

<p>If a <code>freefunc</code> is supplied it will be called once, when the pointer is garbage collected or when the block is left if a block is supplied or when the user calls <code>call_free</code>, whichever happens first. <code>freefunc</code> must be an address pointing to a function or an instance of <code>Fiddle::Function</code>.</p>

                              <div class="method-source-code" id="malloc-source">
            <pre>static VALUE
rb_fiddle_ptr_s_malloc(int argc, VALUE argv[], VALUE klass)
{
    VALUE size, sym, obj, wrap = 0;
    long s;
    freefunc_t f;

    switch (rb_scan_args(argc, argv, &quot;11&quot;, &amp;size, &amp;sym)) {
      case 1:
        s = NUM2LONG(size);
        f = NULL;
        break;
      case 2:
        s = NUM2LONG(size);
        f = get_freefunc(sym, &amp;wrap);
        break;
      default:
        rb_bug(&quot;rb_fiddle_ptr_s_malloc&quot;);
    }

    obj = rb_fiddle_ptr_malloc(klass, s,f);
    if (wrap) RB_OBJ_WRITE(obj, &amp;RPTR_DATA(obj)-&gt;wrap[1], wrap);

    if (rb_block_given_p()) {
        if (!f) {
            rb_raise(rb_eArgError, &quot;a free function must be supplied to Fiddle::Pointer.malloc when it is called with a block&quot;);
        }
        return rb_ensure(rb_yield, obj, rb_fiddle_ptr_call_free, obj);
    } else {
        return obj;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer.new(address)      &rarr; fiddle_cptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(address, size)                &rarr; fiddle_cptr
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(address, size, freefunc)      &rarr; fiddle_cptr
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Create a new pointer to <code>address</code> with an optional <code>size</code> and <code>freefunc</code>.</p>

<p><code>freefunc</code> will be called when the instance is garbage collected.</p>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_fiddle_ptr_initialize(int argc, VALUE argv[], VALUE self)
{
    VALUE ptr, sym, size, wrap = 0, funcwrap = 0;
    struct ptr_data *data;
    void *p = NULL;
    freefunc_t f = NULL;
    long s = 0;

    if (rb_scan_args(argc, argv, &quot;12&quot;, &amp;ptr, &amp;size, &amp;sym) &gt;= 1) {
        VALUE addrnum = rb_Integer(ptr);
        if (addrnum != ptr) wrap = ptr;
        p = NUM2PTR(addrnum);
    }
    if (argc &gt;= 2) {
        s = NUM2LONG(size);
    }
    if (argc &gt;= 3) {
        f = get_freefunc(sym, &amp;funcwrap);
    }

    if (p) {
        TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
        if (data-&gt;ptr &amp;&amp; data-&gt;free) {
            /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
            (*(data-&gt;free))(data-&gt;ptr);
        }
        RB_OBJ_WRITE(self, &amp;data-&gt;wrap[0], wrap);
        RB_OBJ_WRITE(self, &amp;data-&gt;wrap[1], funcwrap);
        data-&gt;ptr  = p;
        data-&gt;size = s;
        data-&gt;free = f;
    }

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-read" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer.read(address, len)     &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Or read the memory at address <code>address</code> with length <code>len</code> and return a string with that memory</p>

                              <div class="method-source-code" id="read-source">
            <pre>static VALUE
rb_fiddle_ptr_read_mem(VALUE klass, VALUE address, VALUE len)
{
    return rb_str_new((char *)NUM2PTR(address), NUM2ULONG(len));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-to_ptr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer[val]         &rarr; cptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_ptr(val)  &rarr; cptr
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Get the underlying pointer for ruby object <code>val</code> and return it as a <a href="Pointer.html"><code>Fiddle::Pointer</code></a> object.</p>

                              <div class="method-source-code" id="to_ptr-source">
            <pre>static VALUE
rb_fiddle_ptr_s_to_ptr(VALUE self, VALUE val)
{
    VALUE ptr, wrap = val, vptr;

    if (RTEST(rb_obj_is_kind_of(val, rb_cIO))){
        rb_io_t *fptr;
        FILE *fp;
        GetOpenFile(val, fptr);
        fp = rb_io_stdio_file(fptr);
        ptr = rb_fiddle_ptr_new(fp, 0, NULL);
    }
    else if (RTEST(rb_obj_is_kind_of(val, rb_cString))){
        char *str = StringValuePtr(val);
        wrap = val;
        ptr = rb_fiddle_ptr_new(str, RSTRING_LEN(val), NULL);
    }
    else if ((vptr = rb_check_funcall(val, id_to_ptr, 0, 0)) != Qundef){
        if (rb_obj_is_kind_of(vptr, rb_cPointer)){
            ptr = vptr;
            wrap = 0;
        }
        else{
            rb_raise(rb_eFiddleDLError, &quot;to_ptr should return a Fiddle::Pointer object&quot;);
        }
    }
    else{
        VALUE num = rb_Integer(val);
        if (num == val) wrap = 0;
        ptr = rb_fiddle_ptr_new(NUM2PTR(num), 0, NULL);
    }
    if (wrap) RB_OBJ_WRITE(ptr, &amp;RPTR_DATA(ptr)-&gt;wrap[0], wrap);
    return ptr;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-write" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Fiddle::Pointer.write(address, str)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Write bytes in <code>str</code> to the location pointed to by <code>address</code>.</p>

                              <div class="method-source-code" id="write-source">
            <pre>static VALUE
rb_fiddle_ptr_write_mem(VALUE klass, VALUE addr, VALUE str)
{
    memcpy(NUM2PTR(addr), StringValuePtr(str), RSTRING_LEN(str));
    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-2B" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr + n   &rarr; new cptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new pointer instance that has been advanced <code>n</code> bytes.</p>

                              <div class="method-source-code" id="2B-source">
            <pre>static VALUE
rb_fiddle_ptr_plus(VALUE self, VALUE other)
{
    void *ptr;
    long num, size;

    ptr = rb_fiddle_ptr2cptr(self);
    size = RPTR_DATA(self)-&gt;size;
    num = NUM2LONG(other);
    return rb_fiddle_ptr_new((char *)ptr + num, size - num, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2B-40" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">+@</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a dereferenced pointer for this pointer.</p>

<p>Analogous to the star operator in C.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Pointer.html#method-i-ptr">ptr</a>
                            </div>
                          </div>

                  <div id="method-i-2D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr - n   &rarr; new cptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new pointer instance that has been moved back <code>n</code> bytes.</p>

                              <div class="method-source-code" id="2D-source">
            <pre>static VALUE
rb_fiddle_ptr_minus(VALUE self, VALUE other)
{
    void *ptr;
    long num, size;

    ptr = rb_fiddle_ptr2cptr(self);
    size = RPTR_DATA(self)-&gt;size;
    num = NUM2LONG(other);
    return rb_fiddle_ptr_new((char *)ptr - num, size + num, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D-40" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">-@</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a reference pointer for this pointer.</p>

<p>Analogous to the ampersand operator in C.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Pointer.html#method-i-ref">ref</a>
                            </div>
                          </div>

                  <div id="method-i-3C-3D-3E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr &lt;=&gt; other   &rarr; -1, 0, 1, or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns -1 if less than, 0 if equal to, 1 if greater than <code>other</code>.</p>

<p>Returns nil if <code>ptr</code> cannot be compared to <code>other</code>.</p>

                              <div class="method-source-code" id="3C-3D-3E-source">
            <pre>static VALUE
rb_fiddle_ptr_cmp(VALUE self, VALUE other)
{
    void *ptr1, *ptr2;
    SIGNED_VALUE diff;

    if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qnil;

    ptr1 = rb_fiddle_ptr2cptr(self);
    ptr2 = rb_fiddle_ptr2cptr(other);
    diff = (SIGNED_VALUE)ptr1 - (SIGNED_VALUE)ptr2;
    if (!diff) return INT2FIX(0);
    return diff &gt; 0 ? INT2NUM(1) : INT2NUM(-1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr == other    &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if <code>other</code> wraps the same pointer, otherwise returns false.</p>

                              <div class="method-source-code" id="3D-3D-source">
            <pre>static VALUE
rb_fiddle_ptr_eql(VALUE self, VALUE other)
{
    void *ptr1, *ptr2;

    if(!rb_obj_is_kind_of(other, rb_cPointer)) return Qfalse;

    ptr1 = rb_fiddle_ptr2cptr(self);
    ptr2 = rb_fiddle_ptr2cptr(other);

    return ptr1 == ptr2 ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Pointer.html#method-i-eql-3F">eql?</a>
                            </div>

                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr[index]                &rarr; an_integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr[start, length]        &rarr; a_string
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns integer stored at <em>index</em>.</p>

<p>If <em>start</em> and <em>length</em> are given, a string containing the bytes from <em>start</em> of <em>length</em> will be returned.</p>

                              <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
rb_fiddle_ptr_aref(int argc, VALUE argv[], VALUE self)
{
    VALUE arg0, arg1;
    VALUE retval = Qnil;
    size_t offset, len;
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    if (!data-&gt;ptr) rb_raise(rb_eFiddleDLError, &quot;NULL pointer dereference&quot;);
    switch( rb_scan_args(argc, argv, &quot;11&quot;, &amp;arg0, &amp;arg1) ){
      case 1:
        offset = NUM2ULONG(arg0);
        retval = INT2NUM(*((char *)data-&gt;ptr + offset));
        break;
      case 2:
        offset = NUM2ULONG(arg0);
        len    = NUM2ULONG(arg1);
        retval = rb_str_new((char *)data-&gt;ptr + offset, len);
        break;
      default:
        rb_bug(&quot;rb_fiddle_ptr_aref()&quot;);
    }
    return retval;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr[index]         = int                    &rarr;  int
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr[start, length] = string or cptr or addr &rarr;  string or dl_cptr or addr
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Set the value at <code>index</code> to <code>int</code>.</p>

<p>Or, set the memory at <code>start</code> until <code>length</code> with the contents of <code>string</code>, the memory from <code>dl_cptr</code>, or the memory pointed at by the memory address <code>addr</code>.</p>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre>static VALUE
rb_fiddle_ptr_aset(int argc, VALUE argv[], VALUE self)
{
    VALUE arg0, arg1, arg2;
    VALUE retval = Qnil;
    size_t offset, len;
    void *mem;
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    if (!data-&gt;ptr) rb_raise(rb_eFiddleDLError, &quot;NULL pointer dereference&quot;);
    switch( rb_scan_args(argc, argv, &quot;21&quot;, &amp;arg0, &amp;arg1, &amp;arg2) ){
      case 2:
        offset = NUM2ULONG(arg0);
        ((char*)data-&gt;ptr)[offset] = NUM2UINT(arg1);
        retval = arg1;
        break;
      case 3:
        offset = NUM2ULONG(arg0);
        len    = NUM2ULONG(arg1);
        if (RB_TYPE_P(arg2, T_STRING)) {
            mem = StringValuePtr(arg2);
        }
        else if( rb_obj_is_kind_of(arg2, rb_cPointer) ){
            mem = rb_fiddle_ptr2cptr(arg2);
        }
        else{
            mem    = NUM2PTR(arg2);
        }
        memcpy((char *)data-&gt;ptr + offset, mem, len);
        retval = arg2;
        break;
      default:
        rb_bug(&quot;rb_fiddle_ptr_aset()&quot;);
    }
    return retval;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-call_free" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          call_free &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Call the free function for this pointer. Calling more than once will do nothing. Does nothing if there is no free function attached.</p>

                              <div class="method-source-code" id="call_free-source">
            <pre>static VALUE
rb_fiddle_ptr_call_free(VALUE self)
{
    struct ptr_data *pdata;
    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, pdata);
    fiddle_ptr_free_ptr(pdata);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eql-3F" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(other) &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if <code>other</code> wraps the same pointer, otherwise returns false.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Pointer.html#method-i-3D-3D">==</a>
                            </div>
                          </div>

                  <div id="method-i-free" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          free &rarr; Fiddle::Function
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Get the free function for this pointer.</p>

<p>Returns a new instance of <a href="Function.html"><code>Fiddle::Function</code></a>.</p>

<p>See <a href="Function.html#method-c-new"><code>Fiddle::Function.new</code></a></p>

                              <div class="method-source-code" id="free-source">
            <pre>static VALUE
rb_fiddle_ptr_free_get(VALUE self)
{
    struct ptr_data *pdata;
    VALUE address;
    VALUE arg_types;
    VALUE ret_type;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, pdata);

    if (!pdata-&gt;free)
        return Qnil;

    address = PTR2NUM(pdata-&gt;free);
    ret_type = INT2NUM(TYPE_VOID);
    arg_types = rb_ary_new();
    rb_ary_push(arg_types, INT2NUM(TYPE_VOIDP));

    return rb_fiddle_new_function(address, arg_types, ret_type);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-free-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          free=(function)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set the free function for this pointer to <code>function</code> in the given <a href="Function.html"><code>Fiddle::Function</code></a>.</p>

                              <div class="method-source-code" id="free-3D-source">
            <pre>static VALUE
rb_fiddle_ptr_free_set(VALUE self, VALUE val)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    data-&gt;free = get_freefunc(val, &amp;data-&gt;wrap[1]);

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-freed-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          freed? &rarr; bool
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns if the free function for this pointer has been called.</p>

                              <div class="method-source-code" id="freed-3F-source">
            <pre>static VALUE
rb_fiddle_ptr_freed_p(VALUE self)
{
    struct ptr_data *pdata;
    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, pdata);
    return pdata-&gt;freed ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string formatted with an easily readable representation of the internal state of the pointer.</p>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
rb_fiddle_ptr_inspect(VALUE self)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot;:%p ptr=%p size=%ld free=%p&gt;&quot;,
                      RB_OBJ_CLASSNAME(self), (void *)data, data-&gt;ptr, data-&gt;size, (void *)data-&gt;free);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-null-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          null?
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if this is a null pointer.</p>

                              <div class="method-source-code" id="null-3F-source">
            <pre>static VALUE
rb_fiddle_ptr_null_p(VALUE self)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return data-&gt;ptr ? Qfalse : Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ptr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ptr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a dereferenced pointer for this pointer.</p>

<p>Analogous to the star operator in C.</p>

                              <div class="method-source-code" id="ptr-source">
            <pre>static VALUE
rb_fiddle_ptr_ptr(VALUE self)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return rb_fiddle_ptr_new(*((void**)(data-&gt;ptr)),0,0);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Pointer.html#method-i-2B-40">+@</a>
                            </div>

                          </div>

                  <div id="method-i-ref" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ref
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new <a href="Pointer.html"><code>Fiddle::Pointer</code></a> instance that is a reference pointer for this pointer.</p>

<p>Analogous to the ampersand operator in C.</p>

                              <div class="method-source-code" id="ref-source">
            <pre>static VALUE
rb_fiddle_ptr_ref(VALUE self)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return rb_fiddle_ptr_new(&amp;(data-&gt;ptr),0,0);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Pointer.html#method-i-2D-40">-@</a>
                            </div>

                          </div>

                  <div id="method-i-size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Get the size of this pointer.</p>

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
rb_fiddle_ptr_size_get(VALUE self)
{
    return LONG2NUM(RPTR_DATA(self)-&gt;size);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-size-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size=(size)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set the size of this pointer to <code>size</code></p>

                              <div class="method-source-code" id="size-3D-source">
            <pre>static VALUE
rb_fiddle_ptr_size_set(VALUE self, VALUE size)
{
    RPTR_DATA(self)-&gt;size = NUM2LONG(size);
    return size;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_i" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_i
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the integer memory location of this pointer.</p>

                              <div class="method-source-code" id="to_i-source">
            <pre>static VALUE
rb_fiddle_ptr_to_i(VALUE self)
{
    struct ptr_data *data;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return PTR2NUM(data-&gt;ptr);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Pointer.html#method-i-to_int">to_int</a>
                            </div>

                          </div>

                  <div id="method-i-to_int" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_int</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the integer memory location of this pointer.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Pointer.html#method-i-to_i">to_i</a>
                            </div>
                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s        &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s(len)   &rarr; string
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the pointer contents as a string.</p>

<p>When called with no arguments, this method will return the contents until the first NULL byte.</p>

<p>When called with <code>len</code>, a string of <code>len</code> bytes will be returned.</p>

<p>See <a href="Pointer.html#method-i-to_str"><code>to_str</code></a></p>

                              <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
rb_fiddle_ptr_to_s(int argc, VALUE argv[], VALUE self)
{
    struct ptr_data *data;
    VALUE arg1, val;
    int len;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    switch (rb_scan_args(argc, argv, &quot;01&quot;, &amp;arg1)) {
      case 0:
        val = rb_str_new2((char*)(data-&gt;ptr));
        break;
      case 1:
        len = NUM2INT(arg1);
        val = rb_str_new((char*)(data-&gt;ptr), len);
        break;
      default:
        rb_bug(&quot;rb_fiddle_ptr_to_s&quot;);
    }

    return val;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_str" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_str        &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_str(len)   &rarr; string
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the pointer contents as a string.</p>

<p>When called with no arguments, this method will return the contents with the length of this pointer’s <code>size</code>.</p>

<p>When called with <code>len</code>, a string of <code>len</code> bytes will be returned.</p>

<p>See <a href="Pointer.html#method-i-to_s"><code>to_s</code></a></p>

                              <div class="method-source-code" id="to_str-source">
            <pre>static VALUE
rb_fiddle_ptr_to_str(int argc, VALUE argv[], VALUE self)
{
    struct ptr_data *data;
    VALUE arg1, val;
    int len;

    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    switch (rb_scan_args(argc, argv, &quot;01&quot;, &amp;arg1)) {
      case 0:
        val = rb_str_new((char*)(data-&gt;ptr),data-&gt;size);
        break;
      case 1:
        len = NUM2INT(arg1);
        val = rb_str_new((char*)(data-&gt;ptr), len);
        break;
      default:
        rb_bug(&quot;rb_fiddle_ptr_to_str&quot;);
    }

    return val;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_value" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_value
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Cast this pointer to a ruby object.</p>

                              <div class="method-source-code" id="to_value-source">
            <pre>static VALUE
rb_fiddle_ptr_to_value(VALUE self)
{
    struct ptr_data *data;
    TypedData_Get_Struct(self, struct ptr_data, &amp;fiddle_ptr_data_type, data);
    return (VALUE)(data-&gt;ptr);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

